<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<div>
  <div class="btn-group">
    <!-- <a routerLink="/createjob" class="btn btn-primary btn-o btn-wide">
      <i class="fa fa-plus"></i>
       Create Job
    </a> -->
    <a role="button" routerLink="/createjob/batch" class="btn btn-primary btn-o btn-wide dropdown-toggle"
       id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <i class="fa fa-plus"></i>
      Create Job
    </a>
    <ul class="dropdown-menu">
      <!-- <li><a class="dropdown-item" routerLink="/createjob/batch">Batch Job</a></li> -->
      <!-- <li><a class="dropdown-item" routerLink="/createjob/streaming">Streaming Job</a></li> -->
    </ul>
  </div>
  <div id="modelContainer">
    <table class="table table-striped reco" [mfData]="results" #mf="mfDataTable" [mfRowsOnPage]="10">
      <thead>
      <tr style="background-color:#7D95CC">
        <th st-ratio="15">Job Name</th>
        <th st-ratio="15">Previous Fire Time</th>
        <th st-ratio="20">Next Fire Time</th>
        <th st-ratio="15">Job State</th>
        <!-- <th st-ratio="5">Cron Expression</th> -->
        <th st-ratio="5">Action</th>
        <th st-ratio="5">Metric</th>
      </tr>
      </thead>
      <tbody>
      <tr *ngIf="!results">
        <td colspan="7" style="text-align:center;display:none">
          No content!
        </td>
        <!-- <td class="icon" style="border-top-style:none">
          <span class="fa fa-spinner fa-spin fa-3x fa-fw"></span>
        </td> -->
      </tr>
      </tbody>
      <tbody *ngFor="let row of mf.data">
      <tr>
        <td (click)="showInstances(row)" [ngClass]="{accordion:true}" style="cursor: pointer;">
          <i *ngIf="!row.showDetail" class="fa fa-chevron-circle-right blue"></i>
          <i *ngIf="row.showDetail" class="fa fa-chevron-circle-down blue"></i> {{row.jobName}}
          <!-- -{{(row.createTime | date: 'yyyy/MM/dd HH:mm:ss') || 'N/A' }} -->
        </td>
        <td [hidden]="row.previousFireTime!=-1">--/--/-- &nbsp;&nbsp;--:--</td>
        <td [hidden]="row.previousFireTime==-1">{{(row.jobState.previousFireTime | date: 'yyyy/MM/dd HH:mm:ss') || 'N/A'
          }}
        </td>
        <td>{{(row.jobState.nextFireTime | date: 'yyyy/MM/dd HH:mm:ss') || 'N/A' }}</td>
        <td>
            <span *ngIf='row.jobState.state == "NORMAL"' class="normal">{{row.jobState.state}}
                    </span>
          <span *ngIf='row.jobState.state != "NORMAL"' class='unnormal'>{{row.jobState.state}}</span>
        </td>
        <!-- <td>{{row.cronExpression}}</td> -->
        <td>
          &nbsp;
          <a (click)="remove(row)" title="delete" style="text-decoration:none">
            <i class="fa fa-trash-o po"></i>
          </a>&nbsp;
          <a routerLink="/job/{{row.id}}" title="subscribe">
            <i class="fa fa-eye"></i>
          </a>&nbsp;
          <a *ngIf="row.action==='START'" (click)="stateMag(row)" title="Start" style="text-decoration:none">
            <i class="fa fa-play"></i>
          </a>
          <a *ngIf="row.action!=='START'" (click)="stateMag(row)" title="Stop" style="text-decoration:none">
            <i class="fa fa-stop"></i>
          </a>&nbsp;
          <a (click)="trigger(row)" title="trigger now" style="text-decoration:none">
            <i class="fa fa-caret-square-o-right po"></i>
          </a>
        </td>
        <td>
          &nbsp;
          <a (click)="show(row)">
            <i class="fa fa-bar-chart po"></i>
          </a> &nbsp;
        </td>
      </tr>
      <tr *ngIf="row.showDetail">
        <td colspan="7" style="padding:20px 30px 10px 30px;">
          <table class="table table-striped co" [mfData]="allInstances" #mf2="mfDataTable" [mfRowsOnPage]="10">
            <thead>
            <tr style="background-color:#7D95CC">
              <th style="width:30%">AppID</th>
              <th style="width:25%">Time</th>
              <th style="width:20%">State</th>
            </tr>
            </thead>
            <tbody>
            <tr *ngIf="!allInstances">
              <td colspan="7" style="text-align:center">No content.</td>
            </tr>
            <tr *ngFor="let item of mf2.data">
              <td><a href={{item.appUri}} target="_blank" style="color:white">{{item.appId}}</a></td>
              <td>{{item.timestamp | date: 'yyyy/MM/dd HH:mm:ss'}}</td>
              <td>{{item.state}}</td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
              <td class="text-center" colspan="8" style="background-color:#1f1f1f;" id="pagination">
                <mfBootstrapPaginator></mfBootstrapPaginator>
              </td>
            </tr>
            </tfoot>
          </table>
        </td>
      </tr>
      </tbody>
      <tfoot>
      <tr>
        <td colspan="8" class="text-right">
          <mfBootstrapPaginator></mfBootstrapPaginator>
        </td>
      </tr>
      </tfoot>
    </table>
  </div>
  <div class="modal fade" id="deleteJobConfirmation" role="dialog" tabindex="-1" [ngClass]="{'in': visibleAnimate}"
       *ngIf="deletedRow" [ngStyle]="{'display': visible ? 'block' : 'none', 'opacity': visibleAnimate ? 1 : 0}"
       (click)="onContainerClicked($event)">
    <div class="modal-dialog modal-xg modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <toaster-container></toaster-container>
          <h4 class="modal-title">{{modalWndMsg}}</h4>
        </div>
        <div class="modal-body">
          <!-- <ng-include src="'/pages/jobs/delete-confirm.html'"/> -->
          <div class="container-fluid" id="deleteContent" style="overflow:auto;">
            <div class="row">
              <h5 class="over-title margin-bottom-15">Basic information</h5>
            </div>
            <!--//row-->
            <div class="row">
              <div class="col-lg-12 col-md-12 col-sm-12">
                <div id="viewrule-definition" class="viewrule-content">
                  <div class="row">
                    <label class="col-md-4 col-lg-4 col-sm-4">
                      Job Name:
                    </label>
                    <div class="col-md-8 col-lg-8 col-sm-8 " style="color: #fff">
                      {{deletedRow .jobName}}
                    </div>
                  </div>
                  <div class="row">
                    <label for="systemSelector" class="col-md-4 col-lg-4 col-sm-4">
                      Previous Fire Time:
                    </label>
                    <div class="col-md-8 col-lg-8 col-sm-8 " style="color: #fff">
                      {{(deletedRow.jobState.previousFireTime | date: 'yyyy/MM/dd HH:mm:ss') || 'N/A' }}
                    </div>
                  </div>
                  <div class="row">
                    <label for="systemSelector" class="col-md-4 col-lg-4 col-sm-4">
                      Next Fire Time:
                    </label>
                    <div class="col-md-8 col-lg-8 col-sm-8 " style="color: #fff">
                      {{(deletedRow.jobState.nextFireTime | date: 'yyyy/MM/dd HH:mm:ss') || 'N/A' }}
                    </div>
                  </div>
                  <div class="row">
                    <label class="col-md-4 col-lg-4 col-sm-4">
                      Cron Expression:
                    </label>
                    <div class="col-md-8 col-lg-8 col-sm-8" style="color: #fff">
                      {{deletedRow.cronExpression}}
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!--//row-->
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" id="save" class="btn btn-primary" (click)="confirmDelete()">Yes</button>
          <button type="button" class="btn btn-default" data-dismiss="modal" (click)="hide()">No</button>
        </div>
      </div>
    </div>
  </div>
</div>
